<template>
    <button class="jul-button" :class="[`jul-button--${type}`,{'is-round': round},{'is-circle': circle},{'is-disabled': disabled}]"
    @click="handleClick" :disabled="disabled">
        <i v-if="icon" :class="icon"></i>
        <!-- 如果没有传入任何的内容 当我们没有传入插槽的时候  -->
        <span v-if="$slots.default"><slot></slot></span>
    </button>
</template>

<script>
    export default {
        name: 'JulButton',
        // 封装一个通用的组件，会对props做一个约束，props进行校验   props父传子，子接收用的
        props: {
            type: {
                // 约束父传来的数据类型：字符串
                type: String,
                default: 'default'
            },
            round: {
                type: Boolean,
                default: false
            },
            circle: {
                type: Boolean,
                default: false
            },
            icon: {
                type: String,
                default: ''
            },
            disabled: {
                type: Boolean,
                default: false
            }
        },
        methods: {
            handleClick(e) {
                // 子给父派发点击事件
                this.$emit('click', e)
            }
        }
    }
</script>

<style lang="scss">

    .jul-button{
        display: inline-block;
        line-height: 1;
        white-space: nowrap;
        cursor: pointer;
        background: #fff;
        border: 1px solid #dcdfe6;
        color: #333;
        -webkit-appearance:none;
        text-align: center;
        box-sizing: border-box;
        outline: none;
        margin: 0;
        transition: 0.1s;
        font-weight: 500;
        // 禁止文字被选中
        -moz-user-select: none;
        -webkit-user-select: none;
        -ms-user-select: none;
        padding: 10px 18px;
        font-size: 14px;
        border-radius: 4px;
        &:hover,
        &:focus{
            color: #1f1e1e;
            border-color: #c1c4c7;
            background-color: #c1c4c7;
        }
    }
    .jul-button--default {
        background: #fff;
        border: 1px solid #dcdfe6;
        color: #333;
        &:hover,
        &:focus{
            color: #1f1e1e;
            border-color: #c1c4c7;
            background-color: #c1c4c7;
        }
    }

    .jul-button--primary {
        color: #fff;
        background-color: #9e96e4;
        border-color: #9e96e4;
        &:hover,
        &:focus{
            color: #fff;
            background-color: #5848e9;
            border-color: #5848e9;
        }
    }

    .jul-button--success {
        color: #fff;
        background-color: #69ce6e;
        border-color: #69ce6e;
        &:hover,
        &:focus{
            color: #fff;
            background-color: #38943d;
            border-color: #38943d;
        }
    }

    .jul-button--info {
        color: #fff;
        background-color: #71848b;
        border-color: #71848b;
        &:hover,
        &:focus{
            color: #fff;
            background-color: #3b4a50;
            border-color: #3b4a50;
        }
    }

    .jul-button--warning {
        color: #fff;
        background-color: #ec8a09;
        border-color: #ec8a09;
        &:hover,
        &:focus{
            color: #fff;
            background-color: #a86308;
            border-color: #a86308;
        }
    }

    .jul-button--danger {
        color: #fff;
        background-color: #f01212;
        border-color: #f01212;
        &:hover,
        &:focus{
            color: #fff;
            background-color: #aa0606;
            border-color: #aa0606;
        }
    }

    .jul-button.is-round {
        border-radius: 20px;
        padding: 12px 23px;
    }

    .jul-button.is-circle {
        border-radius: 50%;
        padding: 15px;
        line-height: 0;
    }

    // 找到jul-button下 包含有jul-icon-的图标 的后面的 span
    .jul-button [class*=jul-icon-]+span{
        margin-left: 6px;
    }

    .jul-button.is-disabled {
        cursor: not-allowed;
    }
</style>
